package van.planifolia.methodref;

import java.util.function.BiConsumer;
import java.util.function.BiPredicate;
import java.util.function.Predicate;

/**
 * Created by Intellij IDEA<br>
 *
 * @author Planifolia.Van
 * @version 1.0
 * @date 2022/11/4 17:06
 */
public class MethodRef3 {
    public static void main(String[] args) {
        // 创建两个实例对象
        Food food1 = new Food("苹果");
        Food food2 = new Food("小平果");
        // 显然对于一个即有传入值又有返回值的并且返回值为布尔类型我们直接使用断言者函数式接口
//      BiPredicate<Food,Food> biPredicate = (f1,f2)->f1.equals(f2);
        BiPredicate<Food,Food> biPredicate = Food::equals;
        System.out.println(biPredicate.test(food1, food2));
    }
}
class Food{
    String name;
    public Food(String name) {
        this.name = name;
    }
    /**
     * 重写一个equals方法，来作为对象的比较让两个对象只比较name属性
     * @param obj 传入的对象
     * @return 是否相等
     */
    public boolean equals(Food obj) {
        return this.name.equals(obj.name);
    }
}